package com.ftg.learn.mapper;


import com.ftg.learn.common.dto.MemberDto;
import com.ftg.learn.common.vo.MemberVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.ftg.learn.entity.Member;

import java.util.List;

/**
 * @Author 李孝辉
 * @Date 2025/6/16 10:25
 * @email 1626285873@qq.com
 * @Phone 18724505266
 * @内容
 */
@Mapper
public interface MemberMapper{
    @Select("SELECT me.id,me.username,me.rolename,me.icard,me.email,me.phone,me.address,vg.grade_name,ed.education_name,lg.learn_name,me.gmt_create,me.logically_deleted FROM member me\n" +
            "INNER JOIN vip_grade vg ON me.vipgrade_id = vg.id\n" +
            "INNER JOIN learn_grade lg ON me.learngrade_id = lg.id\n" +
            "INNER JOIN education ed ON me.education_id = ed.id")
    List<MemberVo> showAll();

    @Insert("INSERT INTO member(username,password,rolename,icard,email,phone,address) VALUES(#{username},#{password},#{rolename},#{icard},#{email},#{phone},#{address})")
    int addMember(MemberDto memberDto);

    @Update("UPDATE member SET username=#{username},password=#{password},rolename=#{rolename},icard=#{icard},email=#{email},phone=#{phone},address=#{address} WHERE id=#{id}")
    int updateMember(MemberDto memberDto);

    @Update("UPDATE member SET logically_deleted = 0 WHERE id = #{id}")
    int deleteMember(Long id);


    @Update("UPDATE member SET education_threshold = education_threshold + #{Integral} WHERE id = #{id}")
    int TimeIntegral(int Integral, Long id);

    @Update("UPDATE member SET education_threshold = #{threshold} WHERE id=#{id}")
    int updateEducationThreshold(int threshold, int id);

    @Update("UPDATE member SET vipgrade_threshold = #{threshold} WHERE id=#{id}")
    int updateVIPGradeThreshold(int threshold, int id);

    @Update("UPDATE member SET learngrade_threshold = #{threshold} WHERE id=#{id}")
    int updateLearnGradeThreshold(int threshold, int id);

    @Update("UPDATE member SET education_id = #{educationId} WHERE id=#{id}")
    int updateEducationID(int educationId, int id);

    @Update("UPDATE member SET vipgrade_id = #{vipgradeId} WHERE id=#{id}")
    int updateVIPGradeID(int vipGradeId, int id);

    @Update("UPDATE member SET learngrade_id = #{learnGradeId} WHERE id=#{id}")
    int updateLearnGradeID(int learnGradeId, int id);

    @Select("select * from member where id = #{id}")
    Member getMemberById(int id);

    @Update("UPDATE member SET vipgrade_threshold = #{VipGradeThreshold}, earngrade_threshold = #{EducationThreshold} WHERE id = #{id}")
    int LearnIntegral(Long VipGradeThreshold,Long EducationThreshold, Long id);
}
